/**
 *  实际开发中，要注意多线程问题, 可以使用引用数和互斥锁解决
 */
#ifndef __SINGLETON_HPP__
#define __SINGLETON_HPP__

#include <iostream>
using std::cout;
using std::endl;

class Singleton {
public:
	static Singleton *getInstance();
	static void destory();
protected:
	Singleton() { cout<<__func__<<endl; }
	~Singleton() { cout<<__func__<<endl; }
private:
	static Singleton *m_instance;
};

Singleton *Singleton::m_instance = NULL;

inline Singleton *Singleton::getInstance()
{
	cout<<__func__<<endl;
	if (NULL == m_instance) {
		m_instance = new Singleton();
	}

	return m_instance;
}

inline void Singleton::destory()
{
	cout<<__func__<<endl;
	if (m_instance) {
		delete m_instance;
		m_instance = NULL;
	}
}
#endif /* end of include guard */
